#include<stdio.h>
#include<unistd.h>
#include<sys/time.h>

#include"timers.h"

void testTimer(TIMER_DATA, struct timeval *);

void testTimer1(TIMER_DATA, struct timeval *);
void testTimer2(TIMER_DATA, struct timeval *);

int main()
{
    struct timeval stNowTime;
    TIMER_DATA stClientData;
    TIMERS stTable;
    TIMERS stTable2;


    initTmr(&stTable, 20);
    initTmr(&stTable2,1);
    createTmr(&stTable, NULL, testTimer, stClientData, 1000, PERIODIC);
    createTmr(&stTable2, NULL, testTimer2, stClientData, 1000, ONE_SHOT);
    createTmr(&stTable2, NULL, testTimer1, stClientData, 1000, PERIODIC);/*周期性的定时器*/
    while(1)
    {
        static int j = 0;
        sleep(1);
        //        createTmr(NULL, testTimer,stClientData, 1000,0);
         runTmr(&stTable2, &stNowTime);
        gettimeofday(&stNowTime, NULL);
        if (mstimeoutTmr(&stTable,&stNowTime) == 0)
        {
             printf("timeout!\n");
            runTmr(&stTable,&stNowTime);
        }
        j++;
        if (j == 10)
            break;
    }
    destroyTmr(&stTable);
    destroyTmr(&stTable2);
    
    
    return 1;
}

void testTimer(TIMER_DATA client_data, struct timeval* nowP)
{
    static int i = 0;
    printf("hello,this is the table Num:%d time callback!\n",i++);


}
void testTimer1(TIMER_DATA stTimerData, struct timeval *pstNow)
{
    static int i = 0;
    printf("oh,this is the table2  %d periodic test\n", i++);
}
void testTimer2(TIMER_DATA stTimerData, struct timeval *pstNow)
{
    printf("none periodic test\n");
}
